package com.dingtalk.h5app.quickstart.domain.entity;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

@JsonIgnoreProperties(ignoreUnknown = true)
@Getter
@Setter
@ToString
@Entity
public class Widget {
     @Id
     @GenericGenerator(name="idGenerator", strategy="uuid") //这个是hibernate的注解/生成32位UUID
     @GeneratedValue(generator="idGenerator")

     private String id;
    private String appId ;
    private String entryId ;
    private String name;
    private String label;
    private String type;
    private String value;

    @JsonIgnoreProperties("widget")
    @OneToMany(cascade = CascadeType.ALL,fetch = FetchType.EAGER,mappedBy = "widget")
    private List<Cellwidget> cellwidgetList=new ArrayList<>();
/*
    @Transient
    public void addCellwidge(Cellwidget cellwidget){
        cellwidget.setWidgeRelation(this);
    }*/
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Widget widget = (Widget) o;
        return Objects.equals(name, widget.name);
    }

    @Override
    public int hashCode() {

        return Objects.hash(name);
    }
}
